package org.terrier.matching.models.basicmodel;

import org.terrier.utility.ApplicationSetup;

import uk.ac.gla.terrier.statistics.HKGammaFunction;

public class GAMMAcdf extends BasicModel {
	/*
     * gamma pdf 
     */
    double ga = Double.parseDouble(ApplicationSetup.getProperty("distribution.parameter.0", "1.1"));
    double gb = Double.parseDouble(ApplicationSetup.getProperty("distribution.parameter.1", "1.2"));
    
    double gammafirstpart = - ga * Math.log(gb) - Math.log(HKGammaFunction.getValue(ga));

	@Override
	public String getInfo() {
		return "GAMMAcdf_"+ga+"_"+gb;
	}

	@Override
	public double score(double tf, double documentFrequency,
			double termFrequency, double keyFrequency, double documentLength) {
		/*
		 * gamma
		 */	
		double LogGammaValue = gammafirstpart + (ga - 1) * Math.log(tf) - (tf / gb);
		return (1-Math.exp(LogGammaValue))*keyFrequency;
	}
	
	public void initModel(){
		String value = null;
		if ((value = ApplicationSetup.getProperty("distribution.parameter.0", "1.1d"))!=null){
			this.ga = Double.parseDouble(value);
		}
		if ((value = ApplicationSetup.getProperty("distribution.parameter.1", "1.2d"))!=null){
			this.gb = Double.parseDouble(value);
		}
	}

}
